#!/usr/bin/env python
# -*- coding: utf-8 -*-
#===============================================================================
# Copyright 2011 zod.yslin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
# Author: zod.yslin
# Email: 
# File Name: attribute.py
# Description: 
#   1. class attribute
#   2. instance attribute
# Edit History: 
#   2011-08-10    File created.
#===============================================================================
class Demo:
    i = 0 # class attribute
    x = 0 # class attribute
     
    def __init__(self, i):
        self.i = i  # instance attribute
        Demo.i += 1
        Demo.x += 1
     
    def __str__(self):
        return str(self.i)
          
    def hello(self):
        print "hello %d %d %d" % (self.i, Demo.i, Demo.x)

demo1 = Demo(9527)        
demo1.hello()
# 若是類別屬性與實體屬性的識別字相同，實體物件只能存取實體屬性
print demo1.i, demo1.x  # 9527  1, not 1  1

demo2 = Demo(4234)
demo2.hello()
print demo2.i, demo2.x # 4234  2, not 2  2

print "After all, there are", Demo.i, "instances." 
